package com.iotp.service.upload_record;


import com.iotp.dao.upload_record.UploadRecordMapper;
import com.iotp.entity.upload_record.UploadRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("/uploadRecordService")
public class UploadRecordServiceImpl implements UploadRecordService {
    @Autowired
    private UploadRecordMapper uploadRecordMapper;
    @Override
    public void add(UploadRecord uploadRecord) {
        UploadRecord query = new UploadRecord();
        query.setName(uploadRecord.getName());
        List<UploadRecord> res = this.uploadRecordMapper.selectByCondition(query);
        if(res == null || res.isEmpty()){
            this.uploadRecordMapper.insert(uploadRecord);
        }else{
            uploadRecord.setId(res.get(0).getId());
            this.uploadRecordMapper.updateByPrimaryKeySelective(uploadRecord);
        }

    }

    @Override
    public UploadRecord queryByName(String name) {
        UploadRecord query = new UploadRecord();
        query.setName(name);
        List<UploadRecord> res = this.uploadRecordMapper.selectByCondition(query);
        if(null == res || res.isEmpty()){
            return null;
        }else{
            return res.get(0);
        }
    }
}
